package latisi.models {
  import org.restfulx.collections.ModelsCollection;
  import org.restfulx.Rx;
  import org.restfulx.serializers.*;
  import org.restfulx.models.RxModel;
  
  [Resource(name="articles")]
  [Bindable]
  public class Article extends RxModel {
    public static const LABEL:String = "name";

    public var name:String = "";

    public var journal:String = "";

    public var volume:int = 0;

    public var group:String = "";

    public var training:Boolean = false;

    public var shortcom:Boolean = false;

    public var annotateTime:int = 0;

    public var state:String = "";

    [DateTime]
    public var createdAt:Date;

    [HasMany]
    public var tblocks:ModelsCollection;
    
    [HasMany]
    public var pages:ModelsCollection;
    
    [HasMany]
    public var words:ModelsCollection;
    
    [Ignored]
    public var attachmentUrl:String;
    
    public function Article() {
      super(LABEL);
    }

    public function classify():void {
      var url:String = "/articles/" + this.id + "/classify.json";
      Rx.http({
	rootUrl: "http://0.0.0.0:3000",
	    serializer: new JSONSerializer,
	    resultFormat: "text"
	    }).invoke({URL: url, cacheBy: "show"});
    }

  }
}
